<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            width: 500px;
            height: 320px;
            display: flex;
            flex-direction: column;
            margin: 50px auto;
            border: 3px solid #333;
        }

        .box>ul {
            height: 60px;
            display: flex;
        }

        .box>ul>li {
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 30px;
            color: #fff;
            background-color: skyblue;
            cursor: pointer;
        }

        .box>ul>li.active {
            background-color: orange;
        }

        .box>ol {
            flex: 1;
            position: relative;
        }

        .box>ol>li {
            width: 100%;
            height: 100%;
            background-color: purple;
            font-size: 50px;
            color: #fff;
            position: absolute;
            left: 0;
            top: 0;
            display: none;
        }

        .box>ol>li.active {
            display: block;
        }
    </style>
</head>

<body>

    <div class="box" id="box1">
        <ul>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ul>
        <ol>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ol>
    </div>

    <div class="box" id="box2">
        <ul>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
        </ul>
        <ol>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
        </ol>
    </div>

    <div class="box" id="box3">
        <ul>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
        </ul>
        <ol>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
        </ol>
    </div>


    <div class="box" id="box4">
        <ul>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
        </ul>
        <ol>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
        </ol>
    </div>

    <div class="box" id="box5">
        <ul>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>

        </ul>
        <ol>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>

        </ol>
    </div>


    <script>
        // 实例化对象的时候 告诉对象 我想绑定 点击  移入等等  
        // 用户可以不传  默认就是点击事件 
        // {type:'mouseover'} 
        function MyTabs(selector,options) {
            this.ele = document.querySelector(selector);
            // 这个对象所有的按钮 
            this.btns = this.ele.querySelectorAll('ul > li');
            // 这个对象所有的内容
            this.boxs = this.ele.querySelectorAll('ol > li');
            this.options = options || {}; // 如果传递了{type:'mouseover'} 赋值给this.options
            // 没有传递 给它一个空对象  
            this.init()
        }

        MyTabs.prototype.init = function () {
            var data = this.btns;
            var boxs = this.boxs;
            for (let i = 0; i < this.btns.length; i++) {
                // this.btns[i].onclick = function () {
                //     for (let j = 0; j < data.length; j++) {
                //         data[j].classList.remove('active');
                //         boxs[j].classList.remove('active');

                //     }
                //     data[i].classList.add('active');
                //     boxs[i].classList.add('active');

                // }
                this.btns[i].addEventListener(this.options.type || 'click',()=>{
                    for (let j = 0; j < this.btns.length; j++) {
                        this.btns[j].classList.remove('active');
                        this.boxs[j].classList.remove('active');

                    }
                    this.btns[i].classList.add('active');
                    this.boxs[i].classList.add('active');
                });

            }
        }
        var obj1 = new MyTabs('#box1');
        var obj2 = new MyTabs('#box2',{type:'mouseover'});
        var obj3 = new MyTabs('#box3',{type:'dblclick'});
        var obj4 = new MyTabs('#box4',{type:'mouseover'});
        var obj5 = new MyTabs('#box5',{type:'mouseout'});

    </script>


</body>

</html>